﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace CodeGen.TS.Generation.Members
{
    public class TSMethodInfo : IMemberInfo
    {
        //Will be used later in conjunction with ApiController to generate code from methods

        public bool IsArray
        {
            get;
            set;
        }

        public Type OriginalCLRType
        {
            get;
            set;
        }

        public IntegratedTypescriptType ScriptType
        {
            get;
            set;
        }

        public string MemberName
        {
            get;
            set;
        }

        public string ComplexTypeName
        {
            get;
            set;
        }
        public bool UseObservable
        {
            get;
            set;
        }

        public List<TSParameterInfo> Parameters { get; set; }

        public TSMethodInfo(MethodInfo info)
        {
            this.Parameters = new List<TSParameterInfo>();

            this.MemberName = info.Name;
        }

        public string GetDefinition(string intend)
        {
            string parameterString = "";
            foreach(var parameter in this.Parameters)
            {
                parameterString += parameter.GetDefinition()+", ";
            }
            string returnType = this.GetTypeName();
            string returnString = intend + string.Format("{1}({2} success: (result: {0}, textStatus?: string, jqXHR?: JQueryXHR)=>any, fail?: (jqXHR?: JQueryXHR, errorText?: string, errorThrown?: string) => any){{", returnType, MemberName, parameterString);
            returnString += intend + Properties.Settings.Default.IndentString + Environment.NewLine + intend + Properties.Settings.Default.IndentString + "return null;" 
            + Environment.NewLine + intend + "}"; //TODO: Make something more meaningful
            return returnString;
        }
    }
}
